package br.com.felix.fwt.svg.shapes.path;

import java.awt.Point;
import java.util.Arrays;

public class SVGPointsCommand implements SVGCommand {

	private char command;
	private Point[] points;



	public SVGPointsCommand(char command, Point... points) {
		this.command = command;
		this.points = points;
	}



	public String toString() {
		StringBuilder strb = new StringBuilder(String.valueOf(command));
		for (Point p : points) {
			strb.append(p.x).append(",").append(p.y).append(" ");
		}
		return strb.toString();
	}



	public void merge(SVGCommand command) {
		if (this.getSVGCommandLetter() == command.getSVGCommandLetter()) {
			if (command instanceof SVGPointsCommand) {
				SVGPointsCommand other = (SVGPointsCommand) command;
				int length = this.points.length;
				points = Arrays.copyOf(points, length + other.points.length);
				for (int i = length; i < length + other.points.length; i++) {
					points[i] = other.points[i - length];
				}
			}
		}
	}



	@Override
	public char getSVGCommandLetter() {
		return command;
	}
}
